New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

h3

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h3

Tiny JavaScript Server

0.8.6
Source
npm
Version published
Weekly downloads
1.7M
4.34%
Maintainers
1
Weekly downloads
 
Created

What is h3?

The h3 npm package is a high-performance HTTP framework for Node.js, designed to be lightweight and fast. It is often used for building APIs and microservices, providing a simple and efficient way to handle HTTP requests and responses.

What are h3's main functionalities?

Basic HTTP Server

This code demonstrates how to create a basic HTTP server using the h3 package. The server listens on port 3000 and responds with 'Hello, world!' to any incoming requests.

const { createApp } = require('h3');
const { createServer } = require('http');

const app = createApp();

app.use('/', (req, res) => {
  res.end('Hello, world!');
});

createServer(app).listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Middleware Support

This example shows how to use middleware with the h3 package. The middleware logs each incoming request's method and URL before passing control to the next handler.

const { createApp } = require('h3');
const { createServer } = require('http');

const app = createApp();

// Middleware to log requests
app.use((req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
});

app.use('/', (req, res) => {
  res.end('Hello, world!');
});

createServer(app).listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Routing

This code demonstrates how to set up routing with the h3 package. It defines GET and POST routes for the '/hello' path, responding with different messages based on the HTTP method.

const { createApp, useRouter } = require('h3');
const { createServer } = require('http');

const app = createApp();
const router = useRouter();

router.get('/hello', (req, res) => {
  res.end('Hello, GET!');
});

router.post('/hello', (req, res) => {
  res.end('Hello, POST!');
});

app.use(router);

createServer(app).listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Other packages similar to h3

FAQs

Package last updated on 27 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts